<template>

	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		<el-form-item label="标题" prop="name">
			<el-input v-model="ruleForm.name" placeholder="写个标题吧,会有更多赞喔~"></el-input>
		</el-form-item>
		<el-form-item label="内容" prop="desc">
			<el-input type="textarea" v-model="ruleForm.desc" placeholder="写下你此刻的想法吧"></el-input>
		</el-form-item>

		<el-upload action="https://jsonplaceholder.typicode.com/posts/" list-type="picture-card"
			:on-preview="handlePictureCardPreview" :on-remove="handleRemove">
			<i class="el-icon-plus"><br />上传照片</i>

		</el-upload>
		<el-dialog :visible.sync="dialogVisible">
			<img width="100%" :src="dialogImageUrl" alt="">
		</el-dialog>

		<el-form-item style="text-align: right;">
			<el-button type="primary" @click="submitForm('ruleForm')">立即发布</el-button>
			<el-button @click="resetForm('ruleForm')">重写</el-button>
		</el-form-item>
	</el-form>
</template>

<script>
	export default {
		data() {
			return {
				dialogImageUrl: '',
				dialogVisible: false,
				ruleForm: {
					name: '',
					region: '',
					date1: '',
					date2: '',
					delivery: false,
					type: [],
					resource: '',
					desc: ''
				},
				rules: {
					name: [{
							required: true,
							message: '写个标题吧,会有更多赞喔~',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 20,
							message: '长度在 20 个字符内',
							trigger: 'blur'
						}
					],
					region: [{
						required: true,
						message: '请选择活动区域',
						trigger: 'change'
					}],
					date1: [{
						type: 'date',
						required: true,
						message: '请选择日期',
						trigger: 'change'
					}],
					date2: [{
						type: 'date',
						required: true,
						message: '请选择时间',
						trigger: 'change'
					}],
					type: [{
						type: 'array',
						required: true,
						message: '请至少选择一个活动性质',
						trigger: 'change'
					}],
					resource: [{
						required: true,
						message: '？？',
						trigger: 'change'
					}],
					desc: [{
						required: true,
						message: '写下你此刻的想法吧',
						trigger: 'blur'
					}]
				}
			};
		},
		methods: {
			handleRemove(file, fileList) {
				console.log(file, fileList);
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url;
				this.dialogVisible = true;
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						alert('发布动态成功~');
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			}
		}
	}
</script>

<style>
</style>

